#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n=0;  cin>>n;
  priority_queue<int,vector<int>,greater<int> > pq;

  while(n--)
  {
    int i;cin>>i;
    pq.push(i);
  }
  int ans=0;
  while(pq.size()>=2)
  {
    int sum=0;
    sum+=pq.top();  pq.pop();
    sum+=pq.top();  pq.pop();
    ans+=sum;
  }
  cout<<ans<<endl;
  return 0;
}
